package nl.tudelft.jpacman.npc.ghost;

import nl.tudelft.jpacman.board.BoardFactory;
import nl.tudelft.jpacman.board.Square;
import nl.tudelft.jpacman.level.LevelFactory;
import nl.tudelft.jpacman.level.MapParser;
import nl.tudelft.jpacman.npc.Ghost;

import java.util.ArrayList;
import java.util.List;

/**
 * A test helper utility for writing the ghost unit tests.
 * A useful method for retrieving ghosts from your map would be:
 * findUnitInBoard in the Navigation class.
 */
public final class GhostMapParser extends MapParser {

    private final GhostFactory factoryForGhosts;

    /**
     * Creates a new enhanced map parser.
     * This map parser allows users to specify which ghost should be placed
     * at an exact location.
     *
     * @param factoryForLevel The factory providing the NPC objects and the level.
     * @param factoryForBoard The factory to create board elements.
     * @param factoryForGhosts the factory to create the ghosts.
     */
    public GhostMapParser(LevelFactory factoryForLevel, BoardFactory factoryForBoard,
                          GhostFactory factoryForGhosts) {
        super(factoryForLevel, factoryForBoard);
        this.factoryForGhosts = factoryForGhosts;
    }

    @Override
    protected void addSquare(Square[][] gridOfSquares, List<Ghost> listOfGhosts,
                             List<Square> startingPositions, int xCoordinate, int yCoordinate, char character) {
        if (character == 'C') {
            Ghost clydeGhost = factoryForGhosts.createClyde();
            Square ghostSquare = makeGhostSquare(listOfGhosts, clydeGhost);
            gridOfSquares[xCoordinate][yCoordinate] = ghostSquare;
        } else {
            super.addSquare(gridOfSquares, listOfGhosts, startingPositions, xCoordinate, yCoordinate, character);
        }
    }
}
